﻿using System;

namespace winS.Unity
{
    /// <summary>
    /// 延迟调用函数
    /// </summary>
    internal class DelayCallFunction : Function
    {
        internal event Action onCompleted;

        private float delay;

        private readonly Action function;

        internal DelayCallFunction(float delay, Action function)
        {
            this.delay = delay;
            this.function = function;
        }

        internal override void Update(float deltaTime)
        {
            delay -= deltaTime;
            if (delay > 0f) return;
            function?.Invoke();
            onCompleted.Invoke();
        }
    }
}